home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / DELPHI.SWG / 0028_How to determine the current record numb.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  2.0 KB  |  61 lines

  1. {
  2. Q:  "How can I determine the current record number for a dataset?"
  3.  
  4. A:  If the dataset is based upon a Paradox or dBASE table then
  5. the record number can be determined with a couple of calls to
  6. the BDE (as shown below).  The BDE doesn't support record
  7. numbering for datasets based upon SQL tables, so if your server
  8. supports record numbering you will need to refer to its
  9. documentation.
  10.  
  11.     The following function is given as part of a whole unit and
  12. takes as its parameter any component derived from TDataset
  13. (i.e. TTable, TQuery, TStoredProc) and returns the current
  14. record number (greater than zero) if it is a Paradox or dBASE
  15. table.  Otherwise, the function returns zero.
  16.  
  17.  
  18.     NOTE: for dBASE tables the record number returned is always
  19. the physical record number.  So, if your dataset is a TQuery or
  20. you have a range set on your dataset then the number returned
  21. won't necessarily be relative to the dataset being viewed,
  22. rather it will be based on the record's physical position in
  23. the underlying dBASE table.
  24. }
  25.  
  26. uses
  27.   DB, DBTables, DbiProcs, DbiTypes, DbiErrs;
  28.  
  29. function GetRecordNumber(Dataset: TDataset): Longint;
  30. var
  31.   CursorProps: CurProps;
  32.   RecordProps: RECProps;
  33. begin
  34.   { Return 0 if dataset is not Paradox or dBASE }
  35.   Result := 0;
  36.   with Dataset do
  37.   begin
  38.     { Is the dataset active? }
  39.     if State = dsInactive then
  40.       raise EDatabaseError.Create('Cannot perform this operation '+
  41.                                   'on a closed dataset');
  42.  
  43.     { We need to make this call to grab the cursor's iSeqNums }
  44.     Check(DbiGetCursorProps(Handle, CursorProps));
  45.  
  46.     { Synchronize the BDE cursor with the Dataset's cursor }
  47.     UpdateCursorPos;
  48.  
  49.     { Fill RecordProps with the current record's properties }
  50.     Check(DbiGetRecord(Handle, dbiNOLOCK, nil, @RecordProps));
  51.  
  52.     { What kind of dataset are we looking at? }
  53.     case CursorProps.iSeqNums of
  54.       0: Result := RecordProps.iPhyRecNum;  { dBASE   }
  55.       1: Result := RecordProps.iSeqNum;     { Paradox }
  56.     end;
  57.   end;
  58. end;
  59.  
  60. end.
  61.